package com.wss.dao;

import com.wss.domain.Comment;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 评论dao接口
 */
@Repository
public interface CommentDao {

    /**
     * 查询出所有博客的评论
     * @return
     */
    @Select("select comments.*,btitle,username from comments inner join blog on (b_id=blog.id) inner join account on (comments.u_id=account.id) order by comments.id")
    List<Comment> findBlogCommentAll();

    /**
     * 查询出所有视频的评论
     * @return
     */
    @Select("select comments.*,vtitle,username from comments inner join video on (v_id=video.id) inner join account on (comments.u_id=account.id) order by comments.id")
    List<Comment> findVideoCommentAll();

    /**
     * 根据博客id查询评论
     * @param b_id
     * @return
     */
    @Select("select comments.*,username from comments inner join account on (b_id = #{b_id} and u_id=account.id) order by comments.id")
    List<Comment> findCommentByBlogId(int b_id);

    /**
     * 根据视频id查询评论
     * @param v_id
     * @return
     */
    @Select("select comments.*,username from comments inner join account on (v_id = #{v_id} and u_id=account.id) order by comments.id")
    List<Comment> findCommentByVideoId(int v_id);

    /**
     * 添加评论
     * @param comment
     * @return
     */
    @Insert("insert into comments (cmcontent,cmtime,v_id,b_id,u_id) values (#{cmcontent},curdate(),#{v_id},#{b_id},#{u_id})")
    int addComment(Comment comment);

    /**
     * 删除评论
     * @param comment
     * @return
     */
    @Delete("delete comments from comments where id=#{id}")
    int deleteComment(Comment comment);

}
